var _util = require('util/util.js')
var vue = require('./../common/vue')
const _market_service = require('service/market-service');
const _catalog_service = require("service/catalog-service.js");

var new_prod = new vue({
    el: "#new_prod",
    data: {
        categories: [{
            categoryid: 1,
            name: "休闲零食",
            src: "<image src=\"images/fu_shi_chuan_da/kuzi/100.jpg\">"
        },
        {
            categoryid: 2,
            name: "数码产品",
            src: "<image src=\"images/fu_shi_chuan_da/kuzi/100.jpg\">"
        },
        {
            categoryid: 3,
            name: "母婴产品",
            src: "<image src=\"images/fu_shi_chuan_da/kuzi/100.jpg\">"
        },
        ],
        selectcategoryid: "",
        editproductname: "",
        editpicture : "123/153.jpg",
    },
    methods: {
        addprodcut : function () {
            new_prod.editpicture = $("#file-uploader").val()

            new_prod.editpicture = new_prod.editpicture.split(".")[0];
            new_prod.editpicture = new_prod.editpicture.split("/");
            length = new_prod.editpicture.length;
            new_prod.editpicture = new_prod.editpicture[length - 1];
            new_prod.editpicture = new_prod.editpicture.split("\\");
            length = new_prod.editpicture.length;
            new_prod.editpicture = new_prod.editpicture[length - 1];
            console.log(new_prod.editpicture)
            console.log(new_prod.selectcategoryid)
            console.log(new_prod.editproductname)

            _catalog_service.addtwoclass(
                JSON.stringify({
                    name: new_prod.editproductname,
                    categoryid: new_prod.selectcategoryid,
                    pictureid: new_prod.editpicture
                }),
                function (res) {
                    alert("添加成功")
                    console.log(res)
                },
                function (err) {
                    alert("添加失败")
                    console.log(err)
                }
            )
        },
    },
    //初始化vue对象，渲染数据
    created: function () {
        _catalog_service.getAlloneclass(
            function (res) {
                console.log(res)
                new_prod.categories = res;
            },
            function (res) {
                console.log("ERROR..*..")
            }
        )
    },

})